﻿using System;
using System.Globalization;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;

namespace WhackWole
{
    public class BooleanToBrushConverter : IValueConverter
    {
        // 将布尔值转换为Brush对象
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool boolValue && targetType == typeof(Brush))
            {
                {
                    // 根据布尔值返回不同的Brush
                    if (boolValue)
                    {
                        VisualBrush br = new VisualBrush();
                        Grid gd = new Grid();
                            var txt= new TextBlock();
                        gd.Children.Add(txt);
                        txt.Text = "出现一个刘涛";
                        txt.FontSize = 20;
                        gd.Background = Brushes.Red;
                        br.Visual  = gd;
                        return br;
                    }
                    else
                    {
                        VisualBrush br = new VisualBrush();
                        Grid gd = new Grid();
                        var txt = new TextBlock();
                        gd.Children.Add(txt);
                        txt.Text = "刘涛被拍了一巴掌";
                        txt.FontSize = 20;

                        gd.Background = Brushes.Green;
                        br.Visual = gd;
                        return br;

                    }
                }

                // 如果无法转换或目标类型不是Brush，返回null
               
            }
            return null;
            // 从Brush对象转换回布尔值

        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

    }
}